

package com.hexinfo.dmpro.common.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.dto.HotBackupDTO;
import com.hexinfo.dmpro.common.dto.TableSyncDTO;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.common.model.ClusterSparingConf;
import com.hexinfo.dmpro.common.service.ClusterSparingConfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 集群热备配置表
 *
 * @author yemw
 * @date 2023-08-30 14:09:32
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/clustersparingconf" )
@Api(value = "clustersparingconf", tags = "集群热备配置表管理")
public class ClusterSparingConfController {

    private final  ClusterSparingConfService clusterSparingConfService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param clusterSparingConf 集群热备配置表
     * WrapperEnhancer.like(clusterSparingConf); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @AnonymousAccess
    public ResponseEntity<Object> getClusterSparingConfPage(Page page, ClusterSparingConf clusterSparingConf) {
        return ResponseEntity.ok(clusterSparingConfService.queryList(page,clusterSparingConf));
    }


    /**
     * 通过id查询集群热备配置表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(clusterSparingConfService.getById(id));
    }

    /**
     * 新增集群热备配置表
     * @param clusterSparingConf 集群热备配置表
     * @return R
     */
    @ApiOperation(value = "新增集群热备配置表", notes = "新增集群热备配置表")
    @PostMapping
    @AnonymousAccess
    public ResponseEntity<Object> save(@RequestBody ClusterSparingConf clusterSparingConf) {
        return ResponseEntity.ok(clusterSparingConfService.save(clusterSparingConf));
    }

    /**
     * 修改集群热备配置表
     * @param clusterSparingConf 集群热备配置表
     * @return R
     */
    @ApiOperation(value = "修改集群热备配置表", notes = "修改集群热备配置表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody ClusterSparingConf clusterSparingConf) {
        return ResponseEntity.ok(clusterSparingConfService.updateById(clusterSparingConf));
    }

    /**
     * 通过id删除集群热备配置表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除集群热备配置表", notes = "通过id删除集群热备配置表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(clusterSparingConfService.removeById(id));
    }


    /**
     * 首页-热备数据总量
     * @return R
     */
    @ApiOperation(value = "热备数据总量", notes = "热备数据总量")
    @PostMapping("/hotBackupTotal")
    @AnonymousAccess
    public ResponseEntity<Object> hotBackupTotal(@RequestBody HotBackupDTO hotBackupDTO) {
        return ResponseEntity.ok(clusterSparingConfService.hotBackupTotal(hotBackupDTO));
    }


    /**
     * 首页-表同步方式情况
     * @return R
     */
    @ApiOperation(value = "表同步方式情况", notes = "表同步方式情况")
    @PostMapping("/TableSyncTotal")
    @AnonymousAccess
    public ResponseEntity<Object> TableSyncTotal(@RequestBody TableSyncDTO tableSyncDTO) {
        return ResponseEntity.ok(clusterSparingConfService.TableSyncTotal(tableSyncDTO));
    }
}
